{include file="public/layout" /}
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 
<span class="c-gray en">&gt;</span> 权限管理
<span class="c-gray en">&gt;</span> 添加权限资源
<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i>
</a>
</nav>
<body style="background-color: #FFF; overflow: auto;">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
	<form class="form-horizontal" id="adminHandle" method="post">
		<input type="hidden" name="type" value="{$type}">
		<input type="hidden" name="id" value="{$info.id ? $info.id : ''}">
		<div class="ncap-form-default" style="margin-top: 50px;">
			<dl class="row">
				<dt class="tit">
					<label for="name"><em>*</em>权限资源名称</label>
				</dt>
				<dd class="opt">
					<input type="text" value="{$info.name ? $info.name : ''}" name="name" id="name" class="input-text">
					<p class="notic"></p>
				</dd>
			</dl>
			<dl class="row">
				<dt class="tit">
					<label for="group"><em>*</em>所属分组</label>
				</dt>
				<dd class="opt">
					<select class="select" id="group" name="group" style="width: 150px; height: 30px;">
						{foreach name="group" item="vo" key="key" }
							<option value="{$key}" {if isset($info['group']) && $info['group'] == $key}selected="selected"{/if}>{$vo}</option>
						{/foreach}
					</select>
					<span class="err"></span>
					<p class="notic">所属分组</p>
				</dd>
			</dl>
			<dl class="row">
				<dt class="tit">
					<label for="group"><em>*</em>添加权限码</label>
				</dt>
				<dd class="opt">
					<select class="select" id="controller" onblur="get_act_list(this)" style="width: 150px; height: 30px;">
						<option value="">选择控制器</option>
						{if isset($planList)}
							{foreach name="planList" item="vo"}
								<option value="{$vo}">{$vo}</option>
							{/foreach}
						{/if}
					</select>
					<span class="err">@</span>
					<select id="act_list" class="select" style="width: 150px; height: 30px;">
						<option value="">选择控制器</option>
						{if isset($planList)}
							{foreach name="planList" item="vo"}
								<option value="{$vo}">{$vo}</option>
							{/foreach}
						{/if}
					</select>
					<a class="ncap-btn" onclick="add_right()">添加</a>
					<p class="notic">
					</p>
				</dd>
			</dl>
			<dl class="row">
				<dt class="tit">
					<label for="name"><em>*</em>权限码</label>
				</dt>
				<dd class="opt">
					<table>
						<tr><th style="width:80%; font-size: 14px;">权限码</th><th style="width: 50px;text-align: center; font-size: 14px;" >操作</th></tr>
						<tbody id="rightList">
						{if isset($info.right)}
							{foreach name="info.right" item="vo"}
								<tr>
									<td><input name="right[]" type="text" value="{$vo}" class="input-text" style="width:320px;"></td>
									<td style="text-align: center; font-size: 14px;"><a style=" color: red;" class="ncap-btn" href="javascript:;" onclick="$(this).parent().parent().remove();">删除</a></td>
								</tr>
							{/foreach}
						{/if}
						</tbody>
					</table>
				</dd>
			</dl>
			<div class="bot" style="margin:20px 0 0 180px;">
				<a href="JavaScript:void(0);" onclick="adsubmit();" class="btn btn-primary" id="submitBtn">确认提交</a>&nbsp;&nbsp;
				<a href="JavaScript:void(0);" onclick="javascript:history.go(-1);" class="btn btn-success" id="submitBtn">返回上一页</a>
			</div>
		</div>
	</form>
</div>
{include file="public/footer" /}
<script type="text/javascript">
	function add_right(){
		var a = [];
		$('#rightList .form-control').each(function(i,o){
			if($(o).val() != ''){
				a.push($(o).val());
			}
		})
		var ncode = $('#controller').val();
		if(ncode !== ''){
			var temp = ncode+'@'+ $('#act_list').val();
			if($.inArray(temp,a) != -1){
				layer.msg('此权限码已经添加！', {icon: 2,time: 1000});
				return false;
			}
		}
		var strtr = '<tr>';
		if(ncode!= ''){
			strtr += '<td><input type="text" name="right[]" value="'+ncode+'@'+ $('#act_list').val()+'" class="input-text" style="width:320px;"></td>';
		}else{
			strtr += '<td><input type="text" name="right[]" value="" class="input-text" style="width:320px;"></td>';
		}
		strtr += '<td style="text-align: center; font-size:14px;"><a style="color:red;" href="javascript:;" class="ncap-btn" onclick="$(this).parent().parent().remove();">删除</a></td>';
		$('#rightList').append(strtr);
	}
	function get_act_list(obj){
		$.ajax({
			url: "{:U('System/ajax_get_action',array('type'=>$type))}",
			type:'get',
			data: {'controller':$(obj).val()},
			dataType:'html',
			success:function(res){
				$('#act_list').empty().append(res);
			}
		});
	}
	function adsubmit(){
		if($('input[name=name]').val() == ''){
			layer.msg('权限名称不能为空！', {icon: 2,time: 1000});
			return false;
		}

		if($('input[name="right\[\]"]').length == 0){
			layer.msg('权限码不能为空！', {icon: 2,time: 1000});
			return false;
		}
		$('#adminHandle').submit();
	}
</script>
</body>
</html>